﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;

namespace SimpleData.Storage.Common
{
	/// <summary>
	/// Comando de exclusão
	/// </summary>
	internal static class DeleteCommandBuilder
	{
		private const string SqlDeleteCommand = "DELETE FROM dataObject_values WHERE ColumnKey LIKE @Key";


		internal static SqlCommand CreateCommand( this DataObjectRow row, SqlConnection connection )
		{
			SqlCommand cmd = connection.CreateCommand();
			string searchKey = String.Concat( row.Key.ToString(), "%" );

			cmd.CommandType = System.Data.CommandType.Text;
			cmd.CommandText = SqlDeleteCommand;
			cmd.Parameters.Add(
				new SqlParameter( "@Key", System.Data.SqlDbType.VarChar, 500 )
				{
					Direction = System.Data.ParameterDirection.Input,
					Value = searchKey
				} );
			return cmd;
		}
	}

}
